# 请求输入进行自动回复
# 首先读取reply.txt中定义的文件形成字典，匹配上根据定义给出提示回复
def parse_dict(path):
    with open(path, 'r') as file:
        tmp_dict = {}
        for line in file:
            tmp_array = line.split('|')
            tmp_dict[tmp_array[0]] = tmp_array[1].strip()
    return tmp_dict


def tip_info():
    print("我们小小客服，能够回答一些你的问题：支付，物流，支付等，退出请 回复 bye")


def find_ask(q):
    for key, value in reply_dict.items():
        if key in q:
            return value
    return None


if __name__ == '__main__':
    reply_dict = parse_dict('reply.txt')
    tip_info()
    while True:
        question = input("请输入你问题:")
        r = find_ask(question)
        if r:
            print(r)
        elif question == "bye":
            print("再见，谢谢你的支持")
            break
        else:
            print("未能理解你的问题，提示")
            tip_info()
